import pytest
import requests
import json

@pytest.fixture(scope='session')
def setup():
    print("测试开始：")
    print("----------------------------------")

#接口关联的变量一般写在conftest的fixture固件里
@pytest.fixture(scope="session")
def get_token():
    #可以试一试第一种发接口请求的方法，感觉还是比较方便的
    url = "http://127.0.0.1:8080/dar/user/login"
    payload = {
        "user_name": "test",
        "passwd": "123456"
    }
    headers = {"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8"}
    respose = requests.post(url,data = payload,headers=headers)
    return json.loads(respose.text)["token"]